package com.lanou.lenanapp.base;

import android.app.Application;
import android.content.Context;

import com.lanou.lenanapp.entity.greendao.DaoMaster;
import com.lanou.lenanapp.entity.greendao.DaoSession;


/**
 * Created by dllo on 15/10/21.
 */
public class BaseApplication extends Application {

    private static Context context;
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;



    public static DaoMaster getDaoMaster(){
        if (daoMaster == null){//静态方法只能访问静态变量(context)
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, "lanou3g", null);
            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }
        return daoMaster;
    }

    public static  DaoSession getDaoSession(){
        if (daoSession == null){
            if (daoMaster == null)
                getDaoMaster();
            daoSession = daoMaster.newSession();
        }
        return daoSession;
    }


    @Override
    public void onCreate() {
        super.onCreate();


        context = this;
    }

    public static Context getContext(){

        return context;
    }

}
